//
// Created by 吴喆 on 2020/3/4.
//

#ifndef SUMMER_RESOURCEMANAGER_H
#define SUMMER_RESOURCEMANAGER_H

#include <glad/glad.h>
#include <unordered_map>
#include <string>
#include <fstream>
#include <sstream>
#include <dirent.h>
#include <cstdio>

#include "../util/FileUtil.h"

#if __APPLE__

#include <SOIL/stb_image.h>

#else
#include <SOIL/SOIL.h>
#endif

#include "Texture.h"
#include "Shader.h"
#include "../util/Console.h"
#include "../util/ConfigUtil.h"


// 加载资源、着色器
class ResourceManager {
public:
    // Resource storage
    static std::unordered_map<std::string, Shader*> shaders;
    static std::unordered_map<std::string, Texture2D*> textures;

    // Loads (and generates) a shader program from file loading vertex, fragment (and geometry) shader's source code. If gShaderFile is not nullptr, it also loads a geometry shader
    static Shader*
    loadShader(const GLchar *vShaderFile, const GLchar *fShaderFile, const GLchar *gShaderFile, std::string name);

    // Retrieves a stored shader
    static Shader* getShader(std::string name);

    // Loads (and generates) a texture from file
    static Texture2D* loadTexture(const GLchar *file, GLboolean alpha, IMG_TYPE , std::string &name);

    // Retrieves a stored texture
    static Texture2D* getTexture(const std::string &name);

    // Properly de-allocates all loaded resources
    static void clear();

    static void loadTextureFromDir();

private:
    // Private constructor, that is we do not want any actual resource manager objects. Its members and functions should be publicly available (static).
    ResourceManager() = default;

    // Loads and generates a shader from file
//    static Shader
//    loadShaderFromFile(const GLchar *vShaderFile, const GLchar *fShaderFile, const GLchar *gShaderFile = nullptr);

    // Loads a single texture from file
//    static Texture2D loadTextureFromFile(const GLchar *file, GLboolean alpha);
};

#endif //SUMMER_RESOURCEMANAGER_H
